package cn.com.czpb.client.module.actives.activity;

import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import cn.com.czpb.client.R;
import cn.com.czpb.client.app.ToolBarActivityWhite;

import butterknife.BindView;

/**
 * Created by 猪猪侠 on 2017/7/28.
 */

public class HuodongDetailActivity extends ToolBarActivityWhite {
    @BindView(R.id.webview_id)
    WebView webviewId;
    private String url;

    @Override
    public int setMyContentView() {
        return R.layout.activity_huodong_detail;
    }

    @Override
    public void initView() {
        url = getIntent().getStringExtra("url");
        WebSettings webSettings = webviewId.getSettings();
        webSettings.setSavePassword(false);
        webSettings.setJavaScriptEnabled(true);
        webSettings.setSupportZoom(true);//设置缩放
        webSettings.setBuiltInZoomControls(true);//设置出现缩放工具

        webSettings.setUseWideViewPort(true);//扩大比例的缩放
        //自适应屏幕
        webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        webSettings.setLoadWithOverviewMode(true);
        webviewId.setWebViewClient(new WebViewClient());
        webviewId.setOnKeyListener(new View.OnKeyListener() {
            @Override
            public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
                if (keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
                    if (keyCode == KeyEvent.KEYCODE_BACK && webviewId.canGoBack()) {
                        //表示按返回键 时的操作
                        webviewId.goBack(); //后退
                        return true; //已处理 ...
                    }

                }
                return false;
            }
        });
    }

    @Override
    public void initData() {
        webviewId.loadUrl(url);
    }
}
